<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="js/plugins/ui/jquery-ui.min.css">
    <script src="js/plugins/ui/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="js/plugins/ui/jquery-ui.theme.min.css">
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

<script>
    $(function () {
        //清除搜索框
        $("#tags").val("");

        $.get("/travels/commends",{type:2,pageSize:3},function (data) {
            console.log(data);
            $("#travelsCommends").renderValues(data,{
                setHref:function (item, value) {
                    $(item).attr("href",($(item).attr("href")+value));
                }
            });
            $(".carousel-item:first").addClass("active");
        });

        //直接将currentPage写死,那么只会查询到第二页的数据,之前的data数据丢失,所以此处定义一个临时变量存放data的参数
        var dataList=[];
        var currentPage =1;
        var totalPage=0;


        //jrender渲染数据
        function query() {
            $.get("/travels/list",{currentPage:currentPage,pageSize:5},function (data) {
                console.log(data.list);
                $.merge(dataList,data.list);
               $("#allTravels").renderValues({list:dataList},{
                    shref:function (item, value) {
                       var href =$(item).attr("href")+value;
                       $(item).attr("href",href);
                   },
                   setHref:function (item, value) {
                       var href =$(item).attr("href")+value;
                       $(item).attr("href",href);
                   }
               }
              );
                currentPage +=1;
                totalPage = data.pages;

                //浏览量
                $(".detail").on("click",".browse",function () {
                    console.log($(this).data("id"));
                    var id = $(this).data('id');
                    console.log(id);
                    $.get("/travels/"+id+"/browse",function (data) {
                        console.log(data);
                        location.reload();
                    })

                })

            })
        }

        query();

        //滑动分页
        //分页的条件:屏幕的高度+滑动的高度>=文档的高度
        $(window).scroll(function () {
            if($(window).height()+$(window).scrollTop()>=$(document).height()){
                //console.log($(window).height());console.log($(window).scrollTop());console.log($(document).height());
                //判断当前页是否小于等于总页数
                if(currentPage<=totalPage){
                   query();
                }else{
                    $(document).dialog({
                        type : 'notice',
                        infoText: '亲.我也是有限度的',
                        autoClose: 2500,
                        position: 'bottom'  // center: 居中; bottom: 底部
                    });
                }
            }
        })

    })

    //注意发送ajax请求需要时间(滞后性)-----------------------找攻略搜索框------------
    $.get("/travels/search",function (data) {
        //console.log(data);
        var availableTags=data
        $( "#tags" ).autocomplete({
            source: availableTags
        });

    })

    //搜索框
    function myFunction(){
        var title =$("#tags").val();
        //console.log(title);
        $.get("/travels/titles",{title:title},function (data) {
            setTimeout(function () {
                location.href="/travelContent.html?id="+data.id;
            },1000)
        })

    }


</script>

</head>

<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input type="search" onsearch="myFunction()" id="tags" class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends">
            <div  class="carousel-inner" render-loop="list">
                <div class="carousel-item">
                    <div class="border commend">
                        <a href="/travelContent.html?id=" render-fun="setHref" render-key="list.travelId" >
                        <img render-src="list.commendCoverUrl" width="100%" height="200px">
                            <h1 render-html="list.commendTitle"></h1>
                            <small render-html="list.commendSubTitle"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a href="travelContent.html?id=" class="browse" render-fun="shref" render-key="list.id" render-attr="data-id=list.id">
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <a href="userProfiles.html?id=" render-fun="setHref" render-key="list.author.id" >
                            <img  class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span> </a> 在
                        <span class="addr" render-html="list.place.name" ></span>

                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span render-html="list.browse"></span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a href="travelContent.html?id=" class="browse" render-fun="shref" render-key="list.id" name="clickBtn" render-attr="data-id=list.id">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>



</body>
    <script>

       /* var a = $("#clickRate");
        $(".bigimg img").attr("name");

        $("#clickRate").html(a)*/
    </script>
</html>